package com.codenjoy.tdd;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class PrimeFactors {

    public List<Integer> get(int num) {
        List<Integer> resultList = new ArrayList<Integer>();
        if (num == 1) {
            return resultList;
        }

        int firstDivider = getFirstDivider(num);
        resultList.add(firstDivider);
        while (firstDivider < num) {
            num = num / firstDivider;
            firstDivider = getFirstDivider(num);
            resultList.add(firstDivider);
        }
        return resultList;
    }

    public int getFirstDivider(int num) {
        for (int i = 2; i <= Math.sqrt(num); i++) {
            if (num % i == 0) {
                return i;
            }
        }
        return num;
    }

}
